package scribble;

import java.awt.*;
import java.awt.event.*;
import java.util.EventListener;
import javax.swing.*;

public class Scribble extends JApplet{
	protected  ScribbleCanvas canvas;
	protected EventListener listener;
	protected boolean isApplet = false;
	
	public Scribble(boolean isApplet){
		this.isApplet = isApplet;
		getContentPane().setLayout(new BorderLayout());
		getContentPane().add(makeCanvas(), BorderLayout.CENTER);
		//listener = makeCanvasListener(canvas);
		canvas.addMouseListener((MouseListener) listener);
		canvas.addMouseMotionListener((MouseMotionListener) listener);
		
	}
	public Scribble(){
		//invoked as an applet
		this(true);
	}
	
	protected Component makeCanvas(){
		canvas = new ScribbleCanvas();
		return canvas;
	}
	
//	protected EventListener makeCanvasListener(ScribbleCanvas canvas) {
//		//return new ScribbleCanvasListener(canvas);
//	}
	
	
	public static void main(String[] args){
		JFrame frame = new JFrame();
		frame.setTitle("Scribble Pad");
		frame.getContentPane().setLayout(new BorderLayout());
		frame.getContentPane().add(new Scribble (false), BorderLayout.CENTER);
		frame.addWindowListener(new AppCloser());
		frame.pack();
		frame.setSize(600, 400);
		frame.show();
	}
	
	static class AppCloser extends WindowAdapter{
		public void windowClosing(WindowEvent e){
			System.exit(0);
		}
	}
	
}
